﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlServerCe;
using System.Collections;
//using System.Windows.Forms;
using System.Data.Common;


namespace ResultsManagementSystem
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void login_Click(object sender, EventArgs e)
        {
            /*获取登陆身份代码
             * 学生：0
             * 教师：1
             * 教务处：2
             * 教务秘书：3
             * 错误：-1
             */
            int characterIndex = this.characterSelect.SelectedIndex;
        }

        private void quit_Click(object sender, EventArgs e)
        {
            //关闭窗口
            this.Close();
        }

        private void loginButton_Click(object sender, EventArgs e)
        {
            //获取登陆身份代码
            int characterIndex = this.characterSelect.SelectedIndex;

            //判断登陆类型
            switch (characterIndex)
            {
                case 0:

                    StudentDao studentDao = new StudentDao();

                    Student student = studentDao.querryStudentByNumber(this.nameText.Text);

                    //判断登陆名和密码
                    if (student != null)
                    {
                        if (this.passwordText.Text != student.getPassword())
                        {
                            MessageBox.Show("用户名或密码错误！");
                        }
                        else
                        {
                            MessageBox.Show("登陆成功！");

                            StudentInterface studentInteface = new StudentInterface(this.nameText.Text);
                            studentInteface.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误！");
                    }

                    break;
                case 1:

                    TeacherDao teacherDao = new TeacherDao();

                    Teacher teacher = teacherDao.querryTeacherByName(this.nameText.Text);

                    //判断登陆名和密码
                    if (teacher != null)
                    {
                        if (this.passwordText.Text != teacher.getPassword())
                        {
                            MessageBox.Show("用户名或密码错误！");
                        }
                        else
                        {
                            MessageBox.Show("登陆成功！");

                            TeacherInterface teacherInterface = new TeacherInterface(teacher.getId());
                            teacherInterface.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误！");
                    }

                    break;
                case 2:

                    AcademicAffairsDao academicAffairsDao = new AcademicAffairsDao();

                    AcademicAffairs academicAffairs = academicAffairsDao.querryAcademicAffairsByName(this.nameText.Text);

                    //判断登陆名和密码
                    if (academicAffairs != null)
                    {
                        if (this.passwordText.Text != academicAffairs.getPassword())
                        {
                            MessageBox.Show("用户名或密码错误！");
                        }
                        else
                        {
                            MessageBox.Show("登陆成功！");

                            AcademicAffairsInterface academicAffairsInterface = new AcademicAffairsInterface();

                            academicAffairsInterface.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误！");
                    }
                    break;
                case 3:


                    AcademicAffairsSecretaryDao academicAffairsSecretaryDao = new AcademicAffairsSecretaryDao();

                    AcademicAffairsSecretary academicAffairsSecretary = academicAffairsSecretaryDao.querryAcademicAffairsSecretaryByName(this.nameText.Text);

                    //判断登陆名和密码
                    if (academicAffairsSecretary != null)
                    {
                        if (this.passwordText.Text != academicAffairsSecretary.getPassword())
                        {
                            MessageBox.Show("用户名或密码错误！");
                        }
                        else
                        {
                            MessageBox.Show("登陆成功！");

                            AcademicAffairsSecretaryInterface academicAffairsSecretaryInterface = new AcademicAffairsSecretaryInterface();

                            academicAffairsSecretaryInterface.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误！");
                    }

                    break;
                default:
                    MessageBox.Show("登陆身份不存在！");
                    break;
            }



        }
    }
}
